﻿using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;

namespace HinduShop.Domain.Models
{
    public class Product
    {
        //[HiddenInput(DisplayValue = false)]
        public virtual int Id { get; set; }
        
        [Required(ErrorMessage = "Введите название")]
        public virtual string Name { get; set; }

        public virtual Category Category { get; set; }

        [DataType(DataType.MultilineText)]
        [Required(ErrorMessage = "Введите описание")]
        public virtual string Description { get; set; }

        [Required]
        [Range(0.01, double.MaxValue, ErrorMessage = "Введите положительную цену")]
        public virtual decimal Price { get; set; }

        public virtual IList<Store> Stores { get; set; }

        public virtual byte[] ImageData { get; set; }

        [HiddenInput(DisplayValue = false)]
        public virtual string ImageMimeType { get; set; }

        public Product() 
        {
            Stores = new List<Store>();
        }

        public virtual void AddStore(Store store)
        {
            store.AddProduct(this);
            Stores.Add(store);
        }

        public override int GetHashCode()
        {
            return Id.GetHashCode();
        }

        public override bool Equals(object obj)
        {
            var other = obj as Product;
            return other != null && other.GetHashCode() == GetHashCode();
        }
    }
}